package part10_代理模式_调用目标对象.p04_反射之动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName: MyInvocationHandler
 * @Author: AllenSun
 * @Date: 2020/3/29 14:12
 */
public class MyInvocationHandler implements InvocationHandler {
    //（1）真实主题
    private Object object;
    //（2）绑定真实操作主题，接收被代理对象（固定写法，万年不变）
    public Object bind(Object object){
        this.object=object;
        return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        Object temp = method.invoke(this.object,objects);
        return temp;
    }
}
